package com.baselibrary.adapter

import android.widget.RelativeLayout
import com.baselibrary.R
import com.baselibrary.bean.ShareItemBean
import com.baselibrary.utils.GlideUtils
import com.baselibrary.utils.ScreenUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * @author: 关忆北、
 * @date: 2022/3/30
 * @Des：
 */
class ShareAdapter : BaseQuickAdapter<ShareItemBean, BaseViewHolder>(R.layout.item_share) {
    private var isUpLayoutParams: Boolean = false
    fun setIsUpLayoutParams(isUpLayoutParams: Boolean) {
        this.isUpLayoutParams = isUpLayoutParams
    }

    override fun convert(helper: BaseViewHolder, item: ShareItemBean) {
        if (isUpLayoutParams) {
            val layoutParams = helper.itemView.layoutParams
            //在这里动态的设置每个 item的宽度根据屏幕的大小来划分
            layoutParams.width = ScreenUtils.getScreenWidth() / itemCount
            helper.itemView.layoutParams = layoutParams
        }

        helper.setText(R.id.tv_share_title, item.title)
        if (item.icon is String) {
            GlideUtils.loadImg_101(mContext, item.icon as String, helper.getView(R.id.circle_share_icon))
        } else if (item.icon is Int) {
            GlideUtils.loadImg_101(mContext, item.icon as Int, helper.getView(R.id.circle_share_icon))
        }
        helper.addOnClickListener(R.id.rl_share_item)
    }
}